package com.rtx.edi.platform.jobextend.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rtx.edi.model.response.EdiResponse;
import com.rtx.edi.platform.jobextend.bean.bo.PlJobBo;
import com.rtx.edi.platform.jobextend.bean.dto.PlJobDTO;
import com.rtx.edi.platform.jobextend.bean.dto.PlJobMappingDTO;
import com.rtx.edi.platform.jobextend.service.PlJobMappingService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = {"调度任务字段映射"})
@RequestMapping("/v1/edi/plJobmapping")
@RestController
public class PlJobMappingController {
	
	@Autowired
	PlJobMappingService plJobMappingService;
	

	@ApiOperation(value = "查询字段配置", notes = "查询字段配置")
	@PostMapping("selectFieldMapping")
	public EdiResponse queryConfig(@RequestBody PlJobMappingDTO dto) throws Exception {
		PlJobBo bo = plJobMappingService.getJobConfig("ris_edi_dev", dto.getJobId());
		Map<String,Object> res = plJobMappingService.getFieldMappingConfig("wmwhse2", bo);
		return EdiResponse.success().data("item",res);
	}
	
	
	
	@ApiOperation(value = "新增字段配置_批量", notes = "新增字段配置_批量")
	@PostMapping("editPlApiMapping")
	public EdiResponse editPlApiMappingStructure(@RequestBody(required = false) PlJobDTO dto) {
		plJobMappingService.addPlJObMapping(dto);
		return EdiResponse.success();
	}
	

	@ApiOperation(value = "执行sql", notes = "执行sql")
	@PostMapping("executeSqlByJobId")
	public EdiResponse executeSqlByJobId(@RequestBody PlJobMappingDTO dto) throws Exception {
		Map<String, List<Map<String, Object>>> list = plJobMappingService.executeSqlByJobId("wmwhse2", dto.getJobId());
		return EdiResponse.success().data("item",list);
	}
}
